import time

import allure
import pytest
from pytest00.tpshop.page.admin_page import Admin_login, Step, Act, rol_data
from pytest00.tpshop.util import Driver, time_data, Data_way, ass, sum1


@allure.epic("tp后台项目")
@allure.feature("tp后台项目test2.py模块哦")
class Test_new:
    def setup_class(self):
        Admin_login.admin_login()
        Step.click_sys()
        Step.click_roul()
    @pytest.mark.parametrize('x,y',[('第1次用户名','第1次邮箱'),('第2次用户名','第2次邮箱')])
    @allure.story("用例描述哦：tp后台项目，验证新建表单")
    @allure.testcase("http://localhost/index.php/Admin/Index/index")
    @allure.severity(allure.severity_level.BLOCKER)
    def test_new(self,x,y):
        n = time_data()[0]
        m = Data_way().monk_data(6)
        nam="%s%d" %(x,n)
        nam2 = "%s%d" %(y,n)
        Act.new_data(nam,nam2 , m)
        n2 = time_data()[1]
        Driver.get_driver().refresh()
        time.sleep(1)

        res=Act.check_data(6)#获取执行结果
        result=(nam, nam2,rol_data(m), n2)
        ass(res, result, res)
        assert res == result

        Act.del_data(nam)#删除

    def teardown_class(self):
        Driver.quit_driver()
        sum1()
class Test_check:
    def setup_class(self):
        Admin_login.admin_login()
        Step.click_sys()
        Step.click_roul()
    def setup_method(self):
        driver=Driver.get_driver()
        driver.refresh()
        time.sleep(1)

    @allure.severity(allure.severity_level.CRITICAL)
    @allure.story("用例描述哦：tp后台项目，验证列表静态查询")
    @allure.testcase("http://localhost/index.php/Admin/Index/index")
    def test_quit(self):
        res=Act.check_data(1)
        result=('admin','admin2','超级管理员','2025-06-20 12:26:38')
        ass(res, result,res)
        assert res == result

    @allure.severity(allure.severity_level.MINOR)
    @allure.story("用例描述哦：tp后台项目，验证列表动态查询")
    @allure.testcase("http://localhost/index.php/Admin/Index/index")
    def test_newdata(self):
        t = time_data()[0]
        m = Data_way().monk_data(6)
        name1="新测试数据%d" %t
        name2="新测试数据-%d" %t
        Act.new_data(name1,name2,m)#新建
        tim = time_data()[1].replace(".", ":")
        Driver.get_driver().refresh()
        time.sleep(1)
        res = Act.check_data(6)
        result = (name1, name2, rol_data(m),tim)
        ass(res, result, res)
        Act.del_data(name1)
        assert res == result

    @allure.severity(allure.severity_level.TRIVIAL)
    @allure.story("用例描述哦：tp后台项目，验证数据删除")
    @allure.testcase("http://localhost/index.php/Admin/Index/index")
    def test_del(self):
        t = time_data()[0]
        m = Data_way().monk_data(6)
        name1 = "新测试数据%d" % t
        name2 = "新测试数据-%d" % t
        Act.new_data(name1, name2, m)  # 新建
        Act.del_data(name1)
        ass("删除成功", "删除成功", "删除成功")
        assert 200 == 200

    def teardown_class(self):
        sum1()
        Driver.quit_driver()


































